package com.qk.management.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.domain.customer.CustomerDO;
import com.qk.dto.customer.CustomerDTO;
import com.qk.dto.customer.CustomerListDTO;
import com.qk.entity.Customer;
import com.qk.management.service.CustomerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * @author diva
 * @date 2025/10/17 8:18
 * @ProjectName
 */
@Slf4j
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @GetMapping
    public Result list(CustomerListDTO dto){
        log.info("==============Controller中的list处理线程名称是={}",Thread.currentThread().getName());
        PageResult<CustomerDO> result = customerService.CustomerList(dto);
        return Result.success(result);
    }

    @PostMapping
    public Result addCustomer(@RequestBody CustomerDTO dto) {
        log.info("==============Controller中的addCustomer处理线程名称是={}",Thread.currentThread().getName());
        customerService.addCustomer(dto);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        log.info("==============Controller中的selectById处理线程名称是={}",Thread.currentThread().getName());
        Customer customer = customerService.selectById(id);
        return Result.success(customer);
    }
    @PutMapping
    public Result updateCustomer(@RequestBody Customer customer) {
        log.info("==============Controller中的updateCustomer处理线程名称是={}",Thread.currentThread().getName());
        customerService.update(customer);
        return Result.success();
    }


}
